import { createStore } from 'vuex'

import movieData from './modules/movie.js'
import homeData from './modules/homeData.js'
import createPersistedState from 'vuex-persistedstate'
import movieLogin from './modules/movieLogin.js'
// 创建一个新的 store 实例
const store = createStore({
  state() {
    return {
      infoId: 0,
      shopInfo: {},
      addressId: ''
    }
  },
  mutations: {
    increment(state, payload) {
      state.infoId = payload
    },
    transformInfo(state, payload) {
      state.shopInfo = payload // 数据赋值给状态里的变量
    },
    getAddressId(state, payload) {
      state.addressId = payload
    }
  },
  plugins: [
    createPersistedState({
      reducer(state) {
        return {
          //单独指明缓存某个module数据
          shopInfo: state.shopInfo,
          movieLogin: state.movielogindata,
          homeData: state.homeData, //单独指明缓存某个module数据,
          movieData: state.movieData,
          cinemaData: state.cinemaData
        }
      }
    })
  ],
  modules: {
    movieData,
    movieLogin,

    homeData
  }
})

export default store
